package com.upb.webserver.common.exception;

import com.upb.webserver.common.returncode.RetCode;
import com.upb.webserver.common.tools.JsonUtils;

public class RestRequestException  extends RuntimeException {

    private static final long serialVersionUID = 1L;
    private RetCode retCode;

    /**
     * init by RetCode.
     */
    public RestRequestException(RetCode retCode) {
        super(retCode.getMessage());
        this.retCode = retCode;
    }

    /**
     * init by RetCode and Throwable.
     */
    public RestRequestException(RetCode retCode, Throwable cause) {
        super(retCode.getMessage(), cause);
        retCode.setMessage(JsonUtils.objToString(cause.getMessage()));
        this.retCode = retCode;
    }

    /**
     * init by code and msg.
     */
    public RestRequestException(int code, String msg) {
        super(msg);
        this.retCode = new RetCode(code, msg);
    }

    /**
     * init by code 、 msg and Throwable.
     */
    public RestRequestException(int code, String msg, Throwable cause) {
        super(msg, cause);
        this.retCode = new RetCode(code, msg);
    }

    public RetCode getRetCode() {
        return retCode;
    }
}
